"""
Case Type   : Compatibility
Case Name   : 验证数组操作函数的bool值输出
Create At   : 2024/10/21
Owner       : liu-tong-8848
Description :
              1.rawlike函数
              2.rawnlike函数
Expect      :
              1.成功
              2.成功
History     :
"""

import os
import unittest

from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from yat.test import Node


class SQL(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.Constant = Constant()
        self.primary_sh = CommonSH('PrimaryDbBmode')
        self.db_user_node = Node(node='PrimaryDbBmode')

    def test_add_dimension(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        step1 = '--step1：=操作符 expect：执行成功'
        self.log.info(step1)
        sql = "select array[1.1,2.1,3.1]::int[] = array[1,2,3] as c; "
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step1)
        sql = "select array[1.1,2.1,4.1]::int[] = array[1,2,5] as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("f", result, "执行失败" + step1)

        step2 = '--step2：<>操作符 expect：执行成功'
        self.log.info(step2)
        sql = "select array[1,2,3] <> array[1,2,4] as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step2)
        sql = "select array[1,2,5] <> array[1,2,5] as c; "
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("f", result, "执行失败" + step2)

        step3 = '--step3：<操作符 expect：执行成功'
        self.log.info(step3)
        sql = "select array[1,2,3] < array[1,2,4] as c; "
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step3)
        sql = "select array[1,2,5] < array[1,2,1] as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("f", result, "执行失败" + step3)

        step4 = '--step4：>操作符 expect：执行成功'
        self.log.info(step4)
        sql = "select array[1,4,3] > array[1,2,4] as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step4)
        sql = "select array[1,2,3] > array[1,2,4] as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("f", result, "执行失败" + step4)

        step5 = ' --step5：<=操作符 expect：执行成功'
        self.log.info(step5)
        sql = "select array[1,2,3] <= array[1,2,3] as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step5)
        sql = "select array[1,2,5] <= array[1,2,3] as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("f", result, "执行失败" + step5)

        step6 = '--step6：>=操作符 expect：执行成功'
        self.log.info(step6)
        sql = "select array[1,2,3] <= array[1,2,3] as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step6)
        sql = "select array[1,2,5] <= array[1,2,3] as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("f", result, "执行失败" + step6)

        step7 = '--step7：@>操作符 expect：执行成功'
        self.log.info(step7)
        sql = "select array[1,4,3] @> array[3,1] as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step7)
        sql = "select array[1,4,3] @> array[3,1,2] as c; "
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("f", result, "执行失败" + step7)

        step8 = '--step8：<@操作符 expect：执行成功'
        self.log.info(step8)
        sql = "select array[2,7] <@ array[1,7,4,2,6] as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step8)
        sql = "select array[1,2,7] <@ array[7,4,2,6] as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("f", result, "执行失败" + step8)

        step9 = '--step9：&&操作符 expect：执行成功'
        self.log.info(step9)
        sql = "select \'array[1,4,3]\' && \'array[2,1]\' as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step9)
        self.assertNotIn("ERROR", result, "执行失败" + step9)
        sql = "select \'array[1,4,3]\' && \'array[2,5]\' as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("f", result, "执行失败" + step9)
        self.assertNotIn("ERROR", result, "执行失败" + step9)

    def tearDown(self):
        self.log.info(f'-----{os.path.basename(__file__)} end-----')
